package com.navinfo.app.hd

import android.app.Activity
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.*
import androidx.annotation.RequiresApi
import androidx.constraintlayout.widget.ConstraintLayout
import com.badlogic.gdx.backends.android.AndroidApplication
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration
import com.badlogic.gdx.backends.android.GdxBaseActivity
import com.badlogic.gdx.graphics.glutils.GLVersion
import com.badlogic.gdx.utils.SharedLibraryLoader
import com.navinfo.collect.library.data.NavinfoPbfData
import com.navinfo.collect.library.data.RealmUtils
import com.navinfo.collect.library.data.entity.GeometryFeatureEntity
import com.navinfo.collect.library.data.entity.LayerEntity
import com.navinfo.collect.library.utils.GeometryTools
import io.realm.Realm
import me.rosuh.filepicker.bean.FileItemBeanImpl
import me.rosuh.filepicker.config.AbstractFileFilter
import me.rosuh.filepicker.config.FilePickerManager
import org.json.JSONArray
import org.locationtech.jts.geom.LineString
import org.oscim.android.canvas.AndroidGraphics
import org.oscim.android.theme.AssetsRenderTheme
import org.oscim.backend.CanvasAdapter
import org.oscim.backend.DateTime
import org.oscim.backend.DateTimeAdapter
import org.oscim.backend.GLAdapter
import org.oscim.core.MapPosition
import org.oscim.core.MercatorProjection
import org.oscim.core.Tag
import org.oscim.core.Tile
import org.oscim.gdx.AndroidGL
import org.oscim.gdx.AndroidGL30
import org.oscim.gdx.GdxAssets
import org.oscim.gdx.GdxMap
import org.oscim.gdx.poi3d.Poi3DLayer
import org.oscim.layers.TileGridLayer
import org.oscim.layers.tile.vector.VectorTileLayer
import org.oscim.layers.tile.vector.labeling.LabelLayer
import org.oscim.map.Map
import org.oscim.model.VtmModels
import java.io.File
import java.io.FileInputStream

class HdGdxActivity: GdxBaseActivity() {
    private val mapViewLayout: LinearLayout by lazy {findViewById(R.id.layout_map)}
    private val gdxMapAndroid: GdxMapAndroid by lazy {GdxMapAndroid(HdGdxActivity@this)}

    fun initGdx(): View {
        AndroidGraphics.init()
        GdxAssets.init("")
        DateTimeAdapter.init(DateTime())

        val metrics = resources.displayMetrics
        CanvasAdapter.dpi = (metrics.density * CanvasAdapter.DEFAULT_DPI).toInt().toFloat()
        Tile.SIZE = Tile.calculateTileSize()

        val cfg = AndroidApplicationConfiguration()
        cfg.stencil = 8
        //cfg.numSamples = 2;

        //cfg.numSamples = 2;
        SharedLibraryLoader().load("vtm-jni")

        return initializeForView(gdxMapAndroid, cfg)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_hd_gdx)
        val gdxView = initGdx()
        val layoutParams = ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        mapViewLayout.addView(gdxView, layoutParams)
    }
}